<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增油枪号')"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-shopProduct-attr-add">
            <div class="form-group">
                <label class="col-sm-3 control-label "><span style="color: red; ">*</span>关联油品：</label>
                <div class="col-sm-4">
                    <select name="productId" class="form-control m-b" th:with="petrolTypeList=${petrolTypeList}">
                        <option th:each="type:${petrolTypeList}" th:value="${type.productId}"
                                th:text="${type.productName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>油枪号：</label>
                <div class="col-sm-4">
                    <input class="form-control" type="text" name="attrName" id="attrName" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>显示排序：</label>
                <div class="col-sm-4">
                    <input class="form-control" type="number" name="orderNum" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>状态：</label>
                <div class="col-sm-4">
                    <div class="radio-box" th:each="dict : ${@dict.getType('show_status')}">
                        <input type="radio" th:id="${dict.dictCode}" name="isEnable" th:value="${dict.dictValue}"
                               th:checked="${dict.default}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer"/>
    <script type="text/javascript">
        var prefix = ctx + "back/shopProduct";


        $("#form-shopProduct-attr-add").validate({
            onkeyup: false,
            rules: {
                attrName: {
                    remote: {
                        url: prefix + "/checkProductAttrNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "attrName": function () {
                                return $.common.trim($("#attrName").val());
                            },
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                orderNum: {
                    digits: true
                }
            },
            messages: {
                "attrName": {
                    remote: "油枪号已存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/attrAdd", $('#form-shopProduct-attr-add').serializeArray());
            }
        }
    </script>
</body>
</html>
